package com.aiwiown.face.internal.parser.json;

import com.aiwiown.face.ApiException;
import com.aiwiown.face.ApiParser;
import com.aiwiown.face.ApiResponse;
import com.aiwiown.face.internal.mapping.Converter;

/**
 * 单个JSON对象解释器。
 *
 * @author carver.gu
 * @since 1.0, Apr 11, 2010
 */
public class ObjectJsonParser<T extends ApiResponse> implements ApiParser<T> {

    private Class<T> clazz;

    public ObjectJsonParser(Class<T> clazz) {
        this.clazz = clazz;
    }
    @Override
    public T parse(String rsp) throws ApiException {
        Converter converter = new JsonConverter();
        return converter.toResponse(rsp, clazz);
    }
    @Override
    public Class<T> getResponseClass() {
        return clazz;
    }

}
